home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Code Resources / SliderCDEF 1.0 / SliderCDEF Source ƒ / SliderUtils.c < prev   
Encoding:
C/C++ Source or Header  |  1993-12-10  |  2.6 KB  |  95 lines  |  [TEXT/KAHL]

  1. #include "SliderCDEF.h"
  2.  
  3. // CalcThumbRect
  4. //
  5. // Calculates the thumb rectangle in window (local) coordinates.
  6. // Should be changed to use fixed-point math.
  7. Rect CalcThumbRect( ControlHandle theControl )
  8. {
  9.     Rect        trackRect;
  10.     short    trackWidth;
  11.     Rect        thumbRect;
  12.     short    thumbWidth;
  13.     short    thumbHalfWidth;
  14.     short    thumbCenter;
  15.     short    val;
  16.     short    max;
  17.     short    min;
  18.     float        ratio;
  19.     
  20.     // Lock the control handle.
  21.     HLock( (Handle) theControl );
  22.     
  23.     // Calculate the thumb width and half-width;
  24.     thumbWidth = kThumbSize;
  25.     thumbHalfWidth = thumbWidth / 2;
  26.     
  27.     // Get a copy of the control's rectangle.
  28.     trackRect = (**theControl).contrlRect;
  29.     
  30.     // Shrink it to the thumb rectangle.
  31.     InsetRect( &trackRect,  thumbHalfWidth + 1, 1 );
  32.     trackWidth = trackRect.right - trackRect.left;
  33.     
  34.     // Get the control's values.
  35.     val = (**theControl).contrlValue;
  36.     max = (**theControl).contrlMax;
  37.     min = (**theControl).contrlMin;
  38.     
  39.     // Unlock the control handle.
  40.     HUnlock( (Handle) theControl );
  41.     
  42.     // Calculate the control's fractional value.
  43.     ratio = ((float)val) / ((float)(max-min));
  44.         
  45.     // Calculate the thumb center.
  46.     thumbCenter = trackRect.left + (short) (ratio * trackWidth);
  47.  
  48.     // Setup the thumb rectangle.
  49.     SetRect( &thumbRect, thumbCenter - thumbHalfWidth,
  50.         trackRect.top, thumbCenter + thumbHalfWidth, trackRect.bottom );
  51.     
  52.     return thumbRect;
  53. }
  54.  
  55.  
  56.  
  57.  
  58. // SliderGetControlColors
  59. //
  60. // Fills in a structure full of colors used by the CDEF to draw the control.
  61. // This routine should use the colors defined by the 'Colors' control panel,
  62. // obtainable through the window's auxilliary color table.
  63. void SliderGetControlColors( ControlHandle theControl, SliderColors *colors )
  64. {
  65.     colors->black.red = colors->black.green = colors->black.blue = 0x0000;
  66.     colors->white.red = colors->white.green = colors->white.blue = 0xFFFF;
  67.  
  68.     colors->darkGray.red = colors->darkGray.green = colors->darkGray.blue = 0x4444;
  69.     colors->lightGray.red = colors->lightGray.green = colors->lightGray.blue = 0xCCCC;
  70.  
  71.     colors->lightColor.red = 0xCCCC;
  72.     colors->lightColor.green = 0xCCCC;
  73.     colors->lightColor.blue = 0xFFFF;
  74.     
  75.     colors->darkColor.red = 0x9999;
  76.     colors->darkColor.green = 0x9999;
  77.     colors->darkColor.blue = 0xCCCC;
  78. }
  79.  
  80.  
  81.  
  82.  
  83. // IsHorizontal
  84. //
  85. // Looks at the control's contrlRect to see whether its width is greater than its height.
  86. // If true, the control is horizontal, otherwise it's vertical.
  87. Boolean IsHorizontal( ControlHandle theControl )
  88. {
  89.     // Make a local copy of the control's rect.
  90.     Rect    theRect = (**theControl).contrlRect;
  91.     
  92.     // Compare the control's width to its height.
  93.     // A perfect place for a conditional expression...
  94.     return ( (theRect.right-theRect.left) > (theRect.bottom-theRect.top) ) ? true : false;
  95. }